package com.zmn.mcc.services.impl.role;

import com.zmn.mcc.model.entity.role.McRoleStaff;
import com.zmn.mcc.persistence.interfaces.role.RoleStaffDao;
import com.zmn.mcc.services.interfaces.role.RoleStaffService;
import org.springframework.stereotype.Service;
import javax.annotation.Resource;
import java.util.ArrayList;
import java.util.List;

/**
 * @author heguanghua
 * @since 2020/04/14 21:44
 */
@Service
public class RoleStaffServiceImpl implements RoleStaffService {

    @Resource
    private RoleStaffDao roleStaffDao;


    @Override
    public McRoleStaff findByKey(Integer roleId, Integer staffId) {
        McRoleStaff roleStaff = new McRoleStaff();
        roleStaff.setRoleId(roleId);
        roleStaff.setStaffId(staffId);
        return this.findByKey(roleStaff);
    }
    @Override
    public McRoleStaff findByKey(McRoleStaff roleStaff) {
        return roleStaffDao.findByKey(roleStaff);
    }

    @Override
    public List<Integer> listStaffIdByRoleId(Integer roleId) {
        return roleStaffDao.listStaffIdByRoleId(roleId);
    }

    @Override
    public List<Integer> listStaffIdBySysId(Integer sysId) {
        return roleStaffDao.listStaffIdBySysId(sysId);
    }

    @Override
    public List<Integer> listRoleIdByStaffId(Integer staffId) {
        return roleStaffDao.listRoleIdByStaffId(staffId);
    }

    /**
     * 描述: 根据角色id列表，查询员工id
     *
     * @param roleIdList 角色id集合
     * @return List<Integer>
     * @author xujie
     * @since 2021/04/28
     **/
    @Override
    public List<Integer> listStaffIdByRoleIdList(List<Integer> roleIdList) {

        if (roleIdList == null || roleIdList.size() == 0) {
            return new ArrayList<>();
        }
        return roleStaffDao.listStaffIdByRoleIdList(roleIdList);
    }

    @Override
    public List<Integer> listPermitBySatffIdAndUrl(Integer staffId, String url) {
        return roleStaffDao.listPermitBySatffIdAndUrl(staffId,url);
    }

    /**
     * 描述: 根据员工id列表，查询角色-授权人员关系
     *
     * @param staffIdList 角色-授权人员关系
     * @return List<McRoleStaff>
     * @author xujie
     * @since 2021/05/28
     **/
    @Override
    public List<McRoleStaff> listRoleStaffByStaffIdList(List<Integer> staffIdList) {

        if (staffIdList == null || staffIdList.size() == 0) {
            return new ArrayList<>();
        }
        return roleStaffDao.listRoleStaffByStaffIdList(staffIdList);
    }

    @Override
    public List<McRoleStaff> listPage(Integer startIndex, Integer pageSize) {

        return roleStaffDao.listPage(startIndex, pageSize);
    }

    @Override
    public Integer countByQuery(McRoleStaff roleStaff) {
        return roleStaffDao.countByQuery(roleStaff);
    }



    @Override
    public Integer insert(McRoleStaff roleStaff) {
        return roleStaffDao.insert(roleStaff);
    }
    
    @Override
    public Integer insertByBatch(List<McRoleStaff> roleStaffes) {
        return roleStaffDao.insertByBatch(roleStaffes);
    }



    @Override
    public Integer deleteByKey(Integer roleId, Integer staffId) {
        McRoleStaff roleStaff = new McRoleStaff();
        roleStaff.setRoleId(roleId);
        roleStaff.setStaffId(staffId);
        return this.deleteByKey(roleStaff);
    }
    @Override
    public Integer deleteByKey(McRoleStaff roleStaff) {
        return roleStaffDao.deleteByKey(roleStaff);
    }
    
    @Override
    public Integer deleteByRoleId(Integer roleId) {
        McRoleStaff roleStaff = new McRoleStaff();
        roleStaff.setRoleId(roleId);
        return this.deleteByQuery(roleStaff);
    }
    @Override
    public Integer deleteByStaffId(Integer staffId) {
        McRoleStaff roleStaff = new McRoleStaff();
        roleStaff.setStaffId(staffId);
        return this.deleteByQuery(roleStaff);
    }
    @Override
    public Integer deleteByQuery(McRoleStaff roleStaff) {
        return roleStaffDao.deleteByQuery(roleStaff);
    }
}
